<template>
	<div class="card__body-container layout-padding">
		<el-card shadow="hover" class="layout-padding-auto">
			<el-form v-show="state.showSearch" :model="state.queryParams" ref="queryFormRef" inline>
				<el-form-item label="团长ID" prop="user_id">
					<el-input v-model="state.queryParams.user_id" placeholder="请输入团长ID" />
				</el-form-item>
				<el-form-item label="团长手机号" prop="user_mobile">
					<el-input v-model="state.queryParams.user_mobile" placeholder="请输入团长手机号" />
				</el-form-item>
				<el-form-item label="团长昵称" prop="user_nickname">
					<el-input v-model="state.queryParams.user_nickname" placeholder="请输入团长昵称" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onQuery">
						<el-icon>
							<ele-Search />
						</el-icon>
						查 询
					</el-button>
					<el-button @click="onResetQuery">
						<el-icon>
							<ele-Refresh />
						</el-icon>
						重 置
					</el-button>
				</el-form-item>
			</el-form>
			<el-row :gutter="10" class="top-block">
				<RightToolbar v-model:showSearch="state.showSearch" @queryTable="getList" />
			</el-row>
			<el-tabs v-model="state.queryParams.type">
				<el-tab-pane label="待审核" :name="1" />
				<el-tab-pane label="审核同意" :name="2" />
				<el-tab-pane label="审核拒绝" :name="4" />
			</el-tabs>
			<el-table :data="state.tableList" v-loading="state.loading">
				<el-table-column label="编号" align="center" prop="id" />
				<el-table-column label="提现单号" align="center" prop="withdraw_no" />
				<el-table-column label="团长信息" align="center" prop="collection_info" width="210">
					<template #default="{ row }">
						<el-row type="flex" justify="center">
							<div style="text-align: left">
								团长ID：{{ row.user_id }}<br />
								团长昵称：{{ row.user_nickname }}<br />
								团长手机号：{{ row.user_mobile }}
							</div>
						</el-row>
					</template>
				</el-table-column>
				<el-table-column label="收款信息" align="center" prop="collection_info" width="150">
					<template #default="{ row }">
						<el-row type="flex" justify="center">
							<div style="text-align: left">
								收款人：{{ row.name }}<br />
								开户行：{{ row.bank_name }}<br />
								提现银行卡号：{{ row.bank_number }}
							</div>
						</el-row>
					</template>
				</el-table-column>
				<el-table-column label="申请提现金额" align="center" prop="apply_money" width="110" />
				<el-table-column label="提现手续费信息" align="center" prop="rate_info" width="140">
					<template #default="{ row }">
						<el-row type="flex" justify="center">
							<div style="text-align: left">
								手续费率：{{ formatterWithdrawRate(row) }}%<br />
								手续费：{{ row.rate_money }}
							</div>
						</el-row>
					</template>
				</el-table-column>
				<el-table-column label="实际到账金额" align="center" prop="remit_money" width="110" />
				<el-table-column label="申请提现时间" align="center" prop="create_time" :formatter="formatterCreateTime" width="110" />
				<template v-if="state.queryParams.type == 4">
					<el-table-column label="审核时间" align="center" prop="check_time" :formatter="formatterCheckTime" />
					<el-table-column label="拒绝原因" align="center" prop="check_fail_reason">
						<template #default="{ row }">
							<el-popover v-if="row.check_fail_reason" placement="top" title="拒绝原因" :width="200" trigger="hover" :content="row.check_fail_reason">
								<template #reference>
									<el-button>查看</el-button>
								</template>
							</el-popover>
							<span v-else>----</span>
						</template>
					</el-table-column>
				</template>

				<el-table-column v-if="state.queryParams.type === 1" label="操作" align="center" prop="operation" fixed="right">
					<template #default="{ row }">
						<el-button type="primary" link @click="onAuditWithdraw(row)"> 审核提现 </el-button>
					</template>
				</el-table-column>
			</el-table>
			<PaginationComponent
				v-if="state.total"
				:total="state.total"
				v-model:page="state.queryParams.pageNum"
				v-model:limit="state.queryParams.pageSize"
				@pagination="getList"
			/>
		</el-card>
		<SupplierWithdrawTrialDialog ref="supplierWithdrawTrialDialogRef" />
	</div>
</template>

<script setup lang="ts" name="colonelWithdrawTrial">
import { onMounted, reactive, ref, defineAsyncComponent, watch } from 'vue';
import { userWithdrawalApi } from '/@/api';
import { floatMultiply, timeDictionary } from '/@/utils/dictionary';

const SupplierWithdrawTrialDialog = defineAsyncComponent(() => import('./dialog/supplierWithdrawTrialDialog.vue'));

const UserWithdrawalApi = userWithdrawalApi();
// 定义变量内容
const state = reactive({
	showSearch: true,
	queryParams: {
		type: 1,
		user_id: '',
		user_nickname: '',
		user_mobile: '',
		pageNum: 1,
		pageSize: 10,
	},
	tableList: [],
	loading: false,
	total: 0,
	supplierIdSelect: {
		loading: false,
		options: [] as any,
	},
	numData: {
		number1: '待审核',
		number2: '审核同意',
		number3: '审核拒绝',
	},
});
const queryFormRef = ref();
const supplierWithdrawTrialDialogRef = ref();

onMounted(() => {
	getList();
});
watch(
	() => state.queryParams.type,
	() => onQuery()
);

/********** 触发事件 **********/
// 查询
const onQuery = () => {
	state.queryParams.pageNum = 1;
	getList();
};
// 重置查询
const onResetQuery = () => {
	queryFormRef.value.resetFields();
	onQuery();
};
// 审核提现
const onAuditWithdraw = (row: Object) => {
	supplierWithdrawTrialDialogRef.value.openDialog(row, () => getList());
};

/********** 方法事件 **********/
// 刷新列表
const getList = () => {
	state.loading = true;
	_usersWithdrawList({
		...state.queryParams,
	});
};
// 提现时间字典
const formatterCreateTime = (row: any) => {
	return timeDictionary(row.create_time);
};
// 审核时间字典
const formatterCheckTime = (row: any) => {
	return timeDictionary(row.check_time);
};
// 手续费率字典
const formatterWithdrawRate = (row: any) => {
	return floatMultiply(row.withdraw_rate, 100);
};

/********** 网络事件 **********/
// 初审列表
const _usersWithdrawList = (params: Object) => {
	UserWithdrawalApi.usersWithdrawList(params)
		.then((res) => {
			state.tableList = res.data.list;
			state.total = res.data.total;
			state.loading = false;
		})
		.catch(() => (state.loading = false));
};
</script>
